package com.lions.client.view.popup;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * 
 * @author Brad
 *
 */
public class MyPopupPanel extends PopupPanel{

	/**
	 * **Still MUST call .center()
	 * **This is only for extending.
	 * **This has no buttons
	 * Call 'super()' to have the default popup border with
	 * the the dimming of the background and a centered popup.
	 * You have to add a panel to the popup.
	 */
	public MyPopupPanel() {
		setSize("100%", "100%");
		setGlassEnabled(true);
		setStyleName("popupwrapper");
	}
	
	/**
	 * **Still MUST call .center()
	 * ** This is only for extending.
	 * ** This has no buttons
	 * Call 'super("My Popup")' to have the default popup border with
	 * the the dimming of the background and a centered popup.
	 * You have to add a panel to the popup.
	 * @param title Tool-tip for the panel
	 */
	public MyPopupPanel(String title) {
		setTitle(title);
		setSize("100%", "100%");
		setGlassEnabled(true);
		setStyleName("popupwrapper");
	}
	
	/**
	 * Simple "OK" popup with custom message message
	 * @param title
	 * @param style
	 */
	public MyPopupPanel(String title, String message) {
		setTitle(title);
		setSize("100%", "100%");
		setGlassEnabled(true);
		setStyleName("popupwrapper");
		
		// Setup Panel
		VerticalPanel messagePanel = new VerticalPanel();
		messagePanel.setStyleName("popup");
		Label text = new Label(message);
		messagePanel.add(text);
		Button okButton = new Button("OK");
		okButton.setStyleName("buttonstyle");
		okButton.addClickHandler(new ClickHandler(){
			@Override
			public void onClick(ClickEvent event) {
				setSize("0", "0");
				hide();
			}
		});
		messagePanel.add(okButton);
		add(messagePanel);
		
		// Print
		center();
	}
	
	/**
	 * Simple "OK" message with custom border
	 * @param title
	 * @param style
	 * @param message
	 */
	public MyPopupPanel(String title, String message, String style) {
		setTitle(title);
		setSize("100%", "100%");
		setGlassEnabled(true);
		setStyleName(style);
		// Setup Panel
		VerticalPanel messagePanel = new VerticalPanel();
		messagePanel.setStyleName("popup");
		Label text = new Label(message);
		messagePanel.add(text);
		Button okButton = new Button("OK");
		okButton.setStyleName("buttonstyle");
		okButton.addClickHandler(new ClickHandler(){
			@Override
			public void onClick(ClickEvent event) {
				hide();
			}
		});
		messagePanel.add(okButton);
		add(messagePanel);
		
		// Print
		center();
	}
	
	/**
	 * Simple "OK / Cancel" popup with custom buttons
	 * @param pan Panel of buttons
	 * @param title Tool-tip name
	 * @param message String for the user
	 */
	public MyPopupPanel(Panel pan, String title, String message) {
		setTitle(title);
		setSize("100%", "100%");
		setGlassEnabled(true);
		setStyleName("popupwrapper");
		
		// Setup Panel
		VerticalPanel messagePanel = new VerticalPanel();
		messagePanel.setStyleName("popup");
		Label text = new Label(message);
		messagePanel.add(text);
		
		// Add items
		messagePanel.add(pan);
		add(messagePanel);
		
		// Print
		center();
	}
	
}
